package com.wh.codedemon.datastructure;

/**
 * 冒泡排序
 */
public class BubbleSort {
    public static void main(String[] args) {
        // int[] array = {3, 21, 56, 7, 3, 13, 4, 65, 23};
        int[] array = {3, 4, 5, 6, 7, 8, 9};

        boolean hasChange = false;
        for (int i = 0; i < array.length - 1; i++) {
            for (int j = 0; j < array.length - i - 1; j++) {
                if (array[j] > array[j + 1]) {
                    hasChange = true;
                    int temp = array[j + 1];
                    array[j + 1] = array[j];
                    array[j] = temp;
                }
            }
            if (hasChange) {
                hasChange = false;
            } else {
                break;
            }
        }
        for (int i : array) {
            System.out.print(i + " ");
        }

    }
}
